import React, { useState } from 'react';
import logo from './logo.svg';
import './App.css';

function App() {
  // const [result, setResult] = useState<null | []>(null)

  // if(result !== null) {
  //   result
  // }

  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <p>
          Edit <code>src/App.tsx</code> and save to reload.
        </p>
        <a
          className="App-link"
          href="https://reactjs.org"
          target="_blank"
          rel="noopener noreferrer"
        >
          Learn React
        </a>
      </header>
    </div>
  );
}

export default App;


// 函数
// function add(num: number, num1: number): number {
//   return num + num1
// }

// const result = add(1, 2)
// console.log(result);

// 函数类型
// 变量声明: 类型 = 值

// let p1: (x: number, y: number) => number = (x: number, y: number): number => {
//   return x + y
// }

// // 变量 = 值
// p1 = (x: number, y: number): number => {
//   return x + y
// }

// 1参数
// 2参数
// 4参数
interface Dir {
  left: number
  top: number
  right: number
  bottom: number
}
// 函数重载: 函数名字一致， 但参数个数和类型不一致的时候， 发生函数重载
function assign(left: number): Dir
function assign(left: number, right: number): Dir
function assign(left: number, right: number, top: number, bottom: number): Dir

function assign(left: number, right?: number, top?: number, bottom?: number) {
  if (right === undefined && top === undefined && bottom === undefined) {
    right = top = bottom = left
  } else if (top === undefined && bottom === undefined) {
    top = left
    bottom = right
  }

  return {
    left, top, bottom, right
  }
}

assign(1)
assign(1, 2)
// 无法执行， 无重载函数
// assign(1, 2, 3)
assign(1, 2, 3, 4)



